<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ include file="/content/variable.jsp" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title></title>
    <%@ include file="/content/head.jsp" %>
</head>
<body>
<div class="row">
    <div class="col-md-12">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">编辑话题详情内容</h3>
            </div>
            <form id="addInfo" class="form-horizontal" role="form">
                <div class="box-body">
                    <!-- 加载编辑器的容器 -->
                    <script id="container" name="content" type="text/plain">
                    </script>
                    <input id="id" type="hidden" name="id" value="${obj.id}">
                    <div class="col-md-offset-5 col-md-9">
                        <button type="submit" class="btn btn-success">确定</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- /.row -->
<%@ include file="/content/js.jsp" %>
<!-- 配置文件 -->
<script type="text/javascript" src="<%=path%>/content/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="<%=path%>/content/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">

</script>
<script type="text/javascript">
    $(function () {

        $('#addInfo').bootstrapValidator({
            message: '此值无效',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {

            }
        }).on('success.form.bv', function (e) {//点击提交之后
            e.preventDefault();
            var $form = $(e.target);
            var bv = $form.data('bootstrapValidator');
            saveInfo();
        });
    });
    var ue = UE.getEditor('container',{
        initialFrameWidth: '100%',
        initialFrameHeight: '300',
        serverUrl:'<%=path%>/ueditor/'
    });


    ue.ready(function() {
        // var xx = $('#msg').val();
        var xx = '${obj.content}';
        ue.setContent(xx);
    });

    UE.Editor.prototype._bkGetActionUrl = UE.Editor.prototype.getActionUrl;
    UE.Editor.prototype.getActionUrl = function(action) {
        if (action == 'uploadimage') {
            return '<%=path%>/korean/video/upload';
        }else {
            return this._bkGetActionUrl.call(this, action);
        }
    }


    function saveInfo() {
        var id = $('#id').val();
        var html = ue.getContent();
        $.post("<%=path%>/topic/topicDeatilSave",
            {"id":id,"content":html}
            , function (data) {
                if (data.missage == "success") {
                    modalMsg("新增成功", "success");
                    window.location.href ='<%=path%>/topic/list';
                }else if(data.missage == "error"){
                    modalMsg("新增失败", "error");
                }else{
                    modalMsg("更新失败", "error");
                }
            }
        );
    }
</script>
</body>
</html>